"use strict";
/*
 * @Author: hongbin
 * @Date: 2023-01-02 20:14:51
 * @LastEditors: hongbin
 * @LastEditTime: 2023-01-04 17:47:43
 * @Description:线性动画 LinearAnimation
 */
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LinearAnimation = void 0;
var LinearAnimation = /** @class */ (function () {
    /**
     * 线性插值运算动画
     */
    function LinearAnimation(start) {
        this.total = 30;
        this.count = 0;
        this.start = start;
    }
    LinearAnimation.prototype.setStart = function (start) {
        this.start = start;
        return this;
    };
    LinearAnimation.prototype.to = function (
    /**
     * 终点对象
     */
    end, 
    /**
     * 调用几次完成变换
     */
    num) {
        this.end = __assign({}, end);
        num && (this.total = num);
        return this;
    };
    LinearAnimation.prototype.onUpdate = function (callback) {
        this.callback = callback;
        return this;
    };
    LinearAnimation.prototype.update = function (progress) {
        var _this = this;
        if (!this.end)
            return;
        if (!progress && this.count >= this.total)
            return;
        var newData = {};
        this.count++;
        var percent = progress
            ? progress > 1
                ? 1
                : progress
            : this.count / this.total;
        //计算当前进度对应的值
        Object.keys(this.start).forEach(function (key) {
            var val = _this.start[key] + (_this.end[key] - _this.start[key]) * percent;
            newData[key] = val;
        });
        this.callback && this.callback(newData);
    };
    return LinearAnimation;
}());
exports.LinearAnimation = LinearAnimation;
